// 获取设置信息promise封装
const getSetting = () => {
    return new Promise((resolve, reject) => {

        wx.getSetting({
            success: (result) => {
                resolve(result)
            },
            fail: (err) => {
                reject(err)
            }
        });
    })
}

// 获取地址信息promise封装
const chooseAddress = () => {
    return new Promise((resolve, reject) => {

        wx.chooseAddress({
            success: (result) => {
                resolve(result)
            },
            fail: (err) => {
                reject(err)
            }
        });
    })
}

// 打开权限promise封装
const openSetting = () => {
    return new Promise((resolve, reject) => {

        wx.openSetting({
            success: (result) => {
                resolve(result)
            },
            fail: (err) => {
                reject(err)
            }
        });
    })
}

/**
 * 模态框是否选择提示
 * @param {object} param0 提示的文本信息
 */
const showModal = ({ content }) => {
    return new Promise((resolve, reject) => {

        wx.showModal({
            title: '提示',
            content: content,
            success: (result) => {
                resolve(result)
            },
            fail: (err) => {
                reject(err)
            }
        });
    })
}

// 登录获取用户信息
const login = () => {
    return new Promise((resolve, reject) => {

        wx.login({
            timeout: 10000,
            success: (result) => {
                resolve(result)
            },
            fail: (err) => {
                reject(err)
            }
        });

    })
}

module.exports = {
    getSetting,
    chooseAddress,
    openSetting,
    showModal,
    login
}